﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using XcoAppSpaces.Security.Basic;

namespace test.XcoAppSpaces.Security.Basic
{
	[TestFixture]
	public class testPasswordUtil
	{
		[Test]
		public void TestEqual()
		{
			byte[] pw1 = PasswordUtil.CreatePasswordHash("thisisapassword1");
			byte[] pw2 = PasswordUtil.CreatePasswordHash("thisisapassword1");

			Assert.IsTrue(PasswordUtil.AreEqual(pw1, pw2));
		}

		[Test]
		public void TestNotEqual()
		{
			byte[] pw1 = PasswordUtil.CreatePasswordHash("thisisapassword1");
			byte[] pw2 = PasswordUtil.CreatePasswordHash("thisisapassword2");

			Assert.IsFalse(PasswordUtil.AreEqual(pw1, pw2));
		}

		[Test]
		public void TestNotEqual2()
		{
			byte[] b1 = new byte[] { 1, 2, 3 };
			byte[] b2 = new byte[] { 1, 2 };

			Assert.IsFalse(PasswordUtil.AreEqual(b1, b2));
		}

		[Test]
		public void TestNotEqual3()
		{
			byte[] b1 = new byte[] { 1, 2 };
			byte[] b2 = new byte[] { 1, 2, 3 };
			
			Assert.IsFalse(PasswordUtil.AreEqual(b1, b2));
		}

		[Test]
		public void TestNull()
		{
			byte[] b = PasswordUtil.CreatePasswordHash(null);

			Assert.IsNull(b);
		}

		[Test]
		public void TestEmpty()
		{
			byte[] b = PasswordUtil.CreatePasswordHash("");

			Assert.IsNull(b);
		}
	}
}
